<?php

namespace app\apisell\model\goods;

use think\Model;

class GoodsModel extends Model
{
    protected $name="sell_goods";

    /**
     * @author: oliver
     * @Description: 分页查询数据列表
     * @param {*} $map  查询条件
     * @param {*} $offset  分页偏移量
     * @param {*} $limit  每页数量
     * @Date: 2024-05-12 14:53:13
     */
    public static function list($map=[], $page=1, $limit=10)
    {
        $offset = 0;
        if ($page > 1) {
            $offset = ((int)$page - 1) * $limit;
        }
        $total = self::where($map)->count();
        $list = self::where($map)->limit($offset, $limit)->order('id desc')->select()->toArray();
        $data = [
            'list' => $list,
            'page' => $page,
            'limit' => $limit,
            'total' => $total
        ];
        return $data;
    }

    public function spec_info()
    {
        return $this->hasMany(GoodsSpecModel::class, 'goods_id', 'id');
    }



}